
import requests

from conn_mysql.conn_mysql import ConnectMysql

class ApiIndex(ConnectMysql):

    def index(self, methods, page, limit):

        if not methods == 'GET':
        
            return {
                'status': -1,
                'errorCode': 4,
                'errorMsg':f'请检查request.method:{methods}请重新请求',
                'resultBody':None
            }
    
        if page == None:
        
            page = '1'

        if limit == None:

            limit = '20'

        if page.isdecimal() and limit.isdecimal(): #检查参数合法性

            page = int(page)

            limit = int(limit)

            sql = 'select * from user_paid ORDER BY regedate DESC limit %s,%s '

            result_info = self.select_all(sql, ((page-1)*limit, limit))

            return {

                    'status': 1,
                    'errorCode': None,
                    'errorMsg':None,
                    'resultBody': result_info,
                }

        else:

            return {
                    'status': -1,
                    'errorCode': 3,
                    'errorMsg':f'请检查page和limit参数是否合法,page:{page},limit:{limit}',
                    'resultBody':None
                }


        

        